var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');

Page({
  data: {
    orderRefundList: [],
    showType: 0,
    page: 1,
    size: 10,
    totalPages: 1
  },
  onLoad: function (options) {
    this.setData({
      showType: 0
    });
  },
  getOrderRefundList() {
    let that = this;
    util.request(api.OrderAftermarketList, {
      showType: that.data.showType,
      page: that.data.page,
      size: that.data.size
    }).then(function (res) {
      if (res.errno === 0) {
        console.log(res.data);
        that.setData({
          orderRefundList: that.data.orderRefundList.concat(res.data.data),
          totalPages: res.data.totalPages
        });
      }
    });
  },
  onReachBottom() {
    if (this.data.totalPages > this.data.page) {
      this.setData({
        page: this.data.page + 1
      });
      this.getOrderRefundList();
    } else {
      wx.showToast({
        title: '没有更多了',
        icon: 'none',
        duration: 2000
      });
      return false;
    }
  },
  onReady: function () {},
  onShow: function () {
    this.setData({
      orderRefundList: [],
      page: 1,
      size: 10,
      totalPages: 1
    });
    this.getOrderRefundList();
  },
  onHide: function () {},
  onUnload: function () {}
})